//
//  WorkSummaryCell.m
//  RSW.IOS
//
//  Created by zhaiqiuqiu on 16/12/22.
//  Copyright © 2016年 com.xtion.crm. All rights reserved.
//

#define HeadImageSize       45

#define BorderLeftRightMargin        10

#define ControlLeftRightMargin          10

#define ControlTopBottomMargin          10

#import "WorkSummaryCell.h"

@interface WorkSummaryCell()
{
    UILabel *_titleLabel;
    UILabel *_contentLabel;
    
    UILabel *_viewCountLabel;
    UILabel *_commentCountLabel;
    UILabel *_createDateLabel;
    
    UILabel *_lineLabel1;
    UILabel *_lineLabel2;
    UILabel *_lineLabel3;
    
    UIView *_backView;
}
@end

@implementation WorkSummaryCell

- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    
    _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(BorderLeftRightMargin, BorderLeftRightMargin, 0, 20)];
    _titleLabel.backgroundColor = [UIColor clearColor];
    _titleLabel.font = [UIFont systemFontOfSize:16];
    //_titleLabel.textColor = [UIColor grayColor];
    [self.contentView addSubview:_titleLabel];
    
    _lineLabel1 = [[UILabel alloc]initWithFrame:CGRectMake(0, _titleLabel.bottom + ControlTopBottomMargin, 0, 0.5)];
    _lineLabel1.backgroundColor = [UIColor grayColor];
    _lineLabel1.alpha = 0.2;
    [self.contentView addSubview:_lineLabel1];
    
    _contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(BorderLeftRightMargin, _lineLabel1.bottom + ControlTopBottomMargin, 0, 20)];
    _contentLabel.backgroundColor = [UIColor clearColor];
    _contentLabel.font = [UIFont systemFontOfSize:16];
    //_contentLabel.textColor = [UIColor grayColor];
    _contentLabel.numberOfLines = 0;
    _contentLabel.lineBreakMode = NSLineBreakByWordWrapping;
    [self.contentView addSubview:_contentLabel];
    
    _lineLabel2 = [[UILabel alloc]initWithFrame:CGRectMake(0, _contentLabel.bottom + ControlTopBottomMargin, 0, 0.5)];
    _lineLabel2.backgroundColor = [UIColor grayColor];
    _lineLabel2.alpha = 0.2;
    [self.contentView addSubview:_lineLabel2];
    
    _backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 20 + ControlTopBottomMargin + ControlTopBottomMargin)];
    [self.contentView addSubview:_backView];
    
    _viewCountLabel = [[UILabel alloc]initWithFrame:CGRectMake(BorderLeftRightMargin, 0, 0, 20)];
    _viewCountLabel.backgroundColor = [UIColor clearColor];
    _viewCountLabel.font = [UIFont systemFontOfSize:16];
    _viewCountLabel.textAlignment = NSTextAlignmentCenter;
    _viewCountLabel.textColor = [UIColor grayColor];
    [_backView addSubview:_viewCountLabel];
    
    _commentCountLabel = [[UILabel alloc]initWithFrame:CGRectMake(0,0, 0, 20)];
    _commentCountLabel.backgroundColor = [UIColor clearColor];
    _commentCountLabel.font = [UIFont systemFontOfSize:16];
    _commentCountLabel.textAlignment = NSTextAlignmentCenter;
    _commentCountLabel.textColor = [UIColor grayColor];
    [_backView addSubview:_commentCountLabel];
    
    _lineLabel3 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 0.5, _backView.height)];
    _lineLabel3.backgroundColor = [UIColor grayColor];
    _lineLabel3.alpha = 0.2;
    [_backView addSubview:_lineLabel3];
    
    _createDateLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 0, 20)];
    _createDateLabel.backgroundColor = [UIColor clearColor];
    _createDateLabel.font = [UIFont systemFontOfSize:16];
    _createDateLabel.textAlignment = NSTextAlignmentCenter;
    _createDateLabel.textColor = [UIColor grayColor];
    [_backView addSubview:_createDateLabel];
    
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];

    CGFloat width = self.contentView.width - BorderLeftRightMargin - BorderLeftRightMargin;
    CGFloat left = BorderLeftRightMargin;
    
    _titleLabel.width = width;
    
    _lineLabel1.width = self.contentView.width;
    
    CGSize contentSize = [_contentLabel.text wrapStringSizeWithFont:_contentLabel.font forWidth:width];
    _contentLabel.frame = CGRectMake(left, _lineLabel1.bottom + ControlTopBottomMargin, width, contentSize.height);
    
    _lineLabel2.top = _contentLabel.bottom + ControlTopBottomMargin;
    _lineLabel2.width = self.contentView.width;
    
    _backView.top = _lineLabel2.bottom;
    _backView.width = self.contentView.width;
    
    _viewCountLabel.top = ControlTopBottomMargin;
    _viewCountLabel.width = self.contentView.width/3 - BorderLeftRightMargin - BorderLeftRightMargin;
    
    _commentCountLabel.top = ControlTopBottomMargin;
    _commentCountLabel.left = self.contentView.width/3 + BorderLeftRightMargin;
    _commentCountLabel.width = self.contentView.width/3 - BorderLeftRightMargin - BorderLeftRightMargin;
    
    _lineLabel3.top = 0;
    _lineLabel3.left = (self.contentView.width*2)/3;
    
    _createDateLabel.top = ControlTopBottomMargin;
    _createDateLabel.left = (self.contentView.width*2)/3 + BorderLeftRightMargin;
    _createDateLabel.width = self.contentView.width/3 - BorderLeftRightMargin - BorderLeftRightMargin;
}


+(CGFloat)caleHeight:(CGFloat)containWidth content:(NSString*)content;
{
    CGFloat height = 0 ;
    
    height = BorderLeftRightMargin;
    height += 20;
    height += ControlTopBottomMargin;
   
    height += ControlTopBottomMargin;
    CGFloat width = containWidth - BorderLeftRightMargin - BorderLeftRightMargin;
    height += [content wrapStringSizeWithFont:[UIFont systemFontOfSize:16] forWidth:width].height;
    height += ControlTopBottomMargin;
    
    height += ControlTopBottomMargin;
    height += 20;
    height += ControlTopBottomMargin;
    
    height += 0.5 * 2;
    
    return height;
}

- (void)setTitle:(NSString *)title
{
    _titleLabel.text = title;
}

- (void)setContent:(NSString *)content
{
    _contentLabel.text = content;
}

- (void)setViewCount:(XMSNumberInt *)viewCount
{
    _viewCountLabel.text = [NSString stringWithFormat:@"阅(%@)",[viewCount toNSString]];
}

- (void)setCommentCount:(XMSNumberInt *)CommentCount
{
    _commentCountLabel.text = [NSString stringWithFormat:@"回复(%@)",[CommentCount toNSString]];
}

- (void)setCreateTime:(NSString *)createTime
{
    _createDateLabel.text = createTime;
}

@end
